package com.zzyl.controller.customer;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ContractVo;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {


    @Autowired
    private ReservationService reservationService;

    //查询取消预约数量
    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> getCancelledReservationCount() {
        //根据取消人id查询取消次数
        Long userId = UserThreadLocal.getUserId();
        Integer count = reservationService.getCancelledReservationCount(userId);
        return success(count);
    }

    //查询每个时间段剩余预约次数
    @GetMapping("/countByTime")
    public ResponseResult countReservationsForEachTimeWithinTimeRange(Long time) {
        List<TimeCountVo> list = reservationService.countReservationsForEachTimeWithinTimeRange(LocalDateTimeUtil.of(time));
        return success(list);
    }

    //新增预约
    @PostMapping
    public ResponseResult add(@RequestBody ReservationDto dto) {
        reservationService.add(dto);
        return success();
    }

        //分页查询预约
    @GetMapping("/page")
    public ResponseResult findByPage(Integer pageNum, Integer pageSize, Integer status) {
        PageResponse<ReservationVo> page = reservationService.findByPage(pageNum,pageSize,status);
        return success(page);
    }

    //取消预约
    @PutMapping("/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return success();
    }
}
